# -*- coding:utf-8 -*-
# created on 2017/4/30
# 

from mathsolver.functions.base import *
from mathsolver.functions.base.base import new_latex


# 在直角△ABC中
class XLRectangularTriangleUpdate(BaseFunction):
    """
    在直角△ABC中,A是△ABC的直角顶点, G是△ABC的重心,|\\overrightarrow{AB}|=2,|\\overrightarrow{AC}|=1,
    则\\overrightarrow{AG}•\\overrightarrow{BC}=
    """
    def solver(self, *args):
        triangle_points = args[0].value
        p1, p2, p3 = triangle_points
        rectangular_triangle = BaseVectorRectangularTriangle(p1, p2, p3)
        self.output.append(rectangular_triangle)
        return self


# 在等腰直角△ABC中
class XLIsOscelesRectangularTriangleUpdate(BaseFunction):
    def solver(self, *args):
        triangle_points = args[0].value
        p1, p2, p3 = triangle_points
        isosceles_rectangular_triangle = BaseVectorIsOscelesRectangularTriangle(p1, p2, p3)
        self.output.append(isosceles_rectangular_triangle)
        return self


# 在等边△ABC中
class XLRegularTriangleUpdate(BaseFunction):
    """
    在边长为1的等边△ABC中,D为BC边上一动点,则\\overrightarrow{AB}•\\overrightarrow{AD}=.
    """
    def solver(self, *args):
        triangle_points = args[0].value
        p1, p2, p3 = triangle_points
        regular_triangle = BaseVectorRegularTriangle(p1, p2, p3)
        self.output.append(regular_triangle)
        return self


# 建系: 在等边三角形△ABC中
class XLRegularTriangleAxisUpdate(BaseFunction):
    def solver(self, *args):
        assert 'vRegularTriangle' in self.known
        known = self.known
        v_zsjx = known['vRegularTriangle']
        v_eqs = v_zsjx.Eqs
        point_a = v_zsjx.A
        point_b = v_zsjx.B
        point_c = v_zsjx.C
        line_to_a_value = sympify('a1')
        v_zsjx.line_To_A_value = line_to_a_value
        v_zsjx.line_To_B_value = line_to_a_value
        v_zsjx.line_To_C_value = line_to_a_value
        v_zsjx.edge_length = line_to_a_value
        v_eqs.append([line_to_a_value, ">", S.Zero])
        self.steps.append(["", "设正三角形的边长为%s" % (new_latex(line_to_a_value))])
        self.steps.append(["", "以%s,%s所在线段为x轴,%s,%s所在线段的中垂线为y轴建立坐标系,得" % (new_latex(point_b), new_latex(point_c), new_latex(point_b), new_latex(point_c))])
        point_a_axis = BasePoint({"name": point_a, "value": [0, sqrt(3) * line_to_a_value / 2]})
        point_b_axis = BasePoint({"name": point_b, "value": [- line_to_a_value / 2, 0]})
        point_c_axis = BasePoint({"name": point_c, "value": [line_to_a_value / 2, 0]})
        self.steps.append(["", "∴ %s, %s, %s" % (point_a_axis.printing(), point_b_axis.printing(), point_c_axis.printing())])
        v_zsjx.A_Axis = point_a_axis
        v_zsjx.B_Axis = point_b_axis
        v_zsjx.C_Axis = point_c_axis
        self.output.append(v_zsjx)
        return self


# 在边长为1的正三角形ABC中
class XLCircumCenterTriangleUpdate(BaseFunction):
    def solver(self, *args):
        triangle_points = args[0].value
        circum_center_triangle_triangle = BaseVectorCircumCenterTriangle(triangle_points)
        self.output.append(circum_center_triangle_triangle)
        return self


# 建系: 已知点F是△ABC外心
class XLCircumCenterTriangleCircumCenterUpdate001(BaseFunction):
    def solver(self, *args):
        assert 'vCircumcenterTriangle' in self.known
        known = self.known
        v_wxsjx = known['vCircumcenterTriangle']
        circum_center = args[0].sympify()
        v_wxsjx.CircumCenter = str(circum_center)
        self.output.append(v_wxsjx)
        return self
